// $codepro.audit.disable numericLiterals
/**
 * Prescription Screen
 * @author Suren Nihalani
 */
package edu.gatech.coc.betameisters.userinterfaces;


import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.JButton;

import edu.gatech.coc.betameisters.infoholders.Prescription;
import edu.gatech.coc.betameisters.main.MainPanel;
import edu.gatech.coc.betameisters.people.Doctor;
import edu.gatech.coc.betameisters.people.Patient;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * The Class Prescription Screen UI.
 * 
 * @author Suren Nihalani
 * @version $REVISION$
 */
@SuppressWarnings("serial")
public class PrescriptionScreenUI extends JPanel {

	/** The my prescription. */
	private Prescription myPrescription; // $codepro.audit.disable com.instantiations.assist.eclipse.analysis.unassignedField

	/** The label prescription. */
	private final JLabel labelPrescription;

	/** The label doctor. */
	private final JLabel labelDoctor;

	/** The label patient. */
	private final JLabel labelPatient;

	/** The label drugname. */
	private final JLabel labelDrugname;

	/** The drugname field. */
	private final JTextField drugnameField;

	/** The label instructions. */
	private final JLabel labelInstructions;

	/** The instructions textpane. */
	private final JTextPane instructionsTextpane;

	/** The label drug price. */
	private final JLabel labelDrugPrice;

	/** The drug pricefield. */
	private final JTextField drugPricefield;

	/** The label drug detials. */
	private final JLabel labelDrugDetials;

	/** The drug details text pane. */
	private final JTextPane drugDetailsTextPane;

	/** The sign it button. */
	private final JButton signItButton;
	
	private MainPanel myParent;
	private Doctor myDoc;

	/**
	 * Create the panel.
	 * 
	 * @param aPrescription
	 *            The Precription object the should be edited or saved changes
	 *            to
	 */
	public PrescriptionScreenUI(Doctor aDoc, Prescription aPrescription, MainPanel p) { // $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.constructorsOnlyInvokeFinalMethods
		
		myParent = p;
		myPrescription = aPrescription;
		myDoc = aDoc;
		final SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);

		labelPrescription = new JLabel("Prescription");
		springLayout.putConstraint(SpringLayout.NORTH, labelPrescription, 10,
				SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, labelPrescription, 169,
				SpringLayout.WEST, this);
		add(labelPrescription);

		labelDoctor = new JLabel("Doctor:"
				+ myPrescription.getMyDoctor().toString());
		springLayout.putConstraint(SpringLayout.NORTH, labelDoctor, 30,
				SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, labelDoctor, 10,
				SpringLayout.WEST, this);
		add(labelDoctor);

		String temp = "";
		if(myPrescription.getMyPatient() != null){
			temp = myPrescription.getMyPatient().toString();
		}
		labelPatient = new JLabel("Patient: "
				+ temp );
		springLayout.putConstraint(SpringLayout.NORTH, labelPatient, 6,
				SpringLayout.SOUTH, labelDoctor);
		springLayout.putConstraint(SpringLayout.WEST, labelPatient, 0,
				SpringLayout.WEST, labelDoctor);
		add(labelPatient);

		labelDrugname = new JLabel("Drugname:");
		springLayout.putConstraint(SpringLayout.NORTH, labelDrugname, 49,
				SpringLayout.SOUTH, labelPatient);
		springLayout.putConstraint(SpringLayout.WEST, labelDrugname, 79, SpringLayout.WEST, this);
		add(labelDrugname);

		drugnameField = new JTextField();
		springLayout.putConstraint(SpringLayout.NORTH, drugnameField, -6,
				SpringLayout.NORTH, labelDrugname);
		springLayout.putConstraint(SpringLayout.WEST, drugnameField, 21,
				SpringLayout.EAST, labelDrugname);
		springLayout.putConstraint(SpringLayout.EAST, drugnameField, -26,
				SpringLayout.EAST, this);
		drugnameField.setText(myPrescription.getDrugName());
		add(drugnameField);
		drugnameField.setColumns(10);

		labelInstructions = new JLabel("Instructions:");
		springLayout.putConstraint(SpringLayout.NORTH, labelInstructions, 6, SpringLayout.SOUTH, labelDrugname);
		springLayout.putConstraint(SpringLayout.WEST, labelInstructions, 79, SpringLayout.WEST, this);
		add(labelInstructions);

		instructionsTextpane = new JTextPane();
		springLayout.putConstraint(SpringLayout.EAST, labelInstructions, -9, SpringLayout.WEST, instructionsTextpane);
		springLayout.putConstraint(SpringLayout.NORTH, instructionsTextpane, 5,
				SpringLayout.SOUTH, drugnameField);
		springLayout.putConstraint(SpringLayout.WEST, instructionsTextpane, 0, SpringLayout.WEST, drugnameField);
		springLayout.putConstraint(SpringLayout.EAST, instructionsTextpane, -79, SpringLayout.EAST, this);
		instructionsTextpane.setText(myPrescription.getDrugInstructions());
		add(instructionsTextpane);

		labelDrugPrice = new JLabel("Drug price; ");
		springLayout.putConstraint(SpringLayout.SOUTH, instructionsTextpane, -6, SpringLayout.NORTH, labelDrugPrice);
		springLayout.putConstraint(SpringLayout.NORTH, labelDrugPrice, 12, SpringLayout.SOUTH, labelInstructions);
		springLayout.putConstraint(SpringLayout.WEST, labelDrugPrice, 89, SpringLayout.WEST, this);
		add(labelDrugPrice);

		drugPricefield = new JTextField();
		springLayout.putConstraint(SpringLayout.NORTH, drugPricefield, 7, SpringLayout.SOUTH, instructionsTextpane);
		springLayout.putConstraint(SpringLayout.WEST, drugPricefield, 0,
				SpringLayout.WEST, labelPrescription);
		springLayout.putConstraint(SpringLayout.EAST, drugPricefield, -26,
				SpringLayout.EAST, this);
		drugPricefield.setText(myPrescription.getDrugPrice());
		add(drugPricefield);
		drugPricefield.setColumns(10);

		labelDrugDetials = new JLabel("Drug Details: ");
		springLayout.putConstraint(SpringLayout.NORTH, labelDrugDetials, 6, SpringLayout.SOUTH, drugPricefield);
		add(labelDrugDetials);

		drugDetailsTextPane = new JTextPane();
		springLayout.putConstraint(SpringLayout.EAST, labelDrugDetials, -5, SpringLayout.WEST, drugDetailsTextPane);
		springLayout.putConstraint(SpringLayout.NORTH, drugDetailsTextPane, 6, SpringLayout.SOUTH, drugPricefield);
		springLayout.putConstraint(SpringLayout.WEST, drugDetailsTextPane, 179, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.EAST, drugDetailsTextPane, -10, SpringLayout.EAST, drugPricefield);
		drugDetailsTextPane.setText(myPrescription.getDrugDetails());
		add(drugDetailsTextPane);

		signItButton = new JButton("Sign It");
		springLayout.putConstraint(SpringLayout.SOUTH, drugDetailsTextPane,
				-21, SpringLayout.NORTH, signItButton);
		signItButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				myPrescription.setDrugName(drugnameField.getText());
				myPrescription.setDrugInstructions(instructionsTextpane
						.getText());
				myPrescription.setDrugPrice(drugPricefield.getText());
				myPrescription.setDrugDetails(drugDetailsTextPane.getText());
				myParent.setPrescrip(myPrescription);
				myParent.setDoctor(myDoc);				
			}
		});
		springLayout.putConstraint(SpringLayout.SOUTH, signItButton, -10,
				SpringLayout.SOUTH, this);
		springLayout.putConstraint(SpringLayout.EAST, signItButton, -10,
				SpringLayout.EAST, this);
		add(signItButton);

	}

	/**
	 * Gets the instructions textpane.
	 * 
	 * @return the instructions textpane
	 */
	public JTextPane getInstructionsTextpane() {
		return instructionsTextpane;
	}

	/**
	 * Gets the drugname field.
	 * 
	 * @return the drugname field
	 */
	public JTextField getDrugnameField() {
		return drugnameField;
	}

	/**
	 * Gets the drug pricefield.
	 * 
	 * @return the drug pricefield
	 */
	public JTextField getDrugPricefield() {
		return drugPricefield;
	}

	/**
	 * Gets the drug details text pane.
	 * 
	 * @return the drug details text pane
	 */
	public JTextPane getDrugDetailsTextPane() {
		return drugDetailsTextPane;
	}
}
